package cn.iocoder.yudao.module.erp.taskListener;

import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent;
import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener;
import cn.iocoder.yudao.module.erp.service.contract.ContractService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 采购合同监听器实现类
 *
 * @author 芋道源码
 */
@Component
@Slf4j
public class PurchaseContractStatusListener extends BpmProcessInstanceStatusEventListener {

    @Resource
    private ContractService contractService;

    @Value("${task.purchase_contract.key:purchase_contract}")
    private String purchaseContract;

    @Override
    protected String getProcessDefinitionKey() {
        return purchaseContract;
    }

    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        log.info("采购合同监听器实现类收到事件：{}", JSON.toJSONString(event));
        Integer status = event.getStatus();
        contractService.updateStatus(Long.parseLong(event.getBusinessKey()), status);

    }

}
